﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.EventBroker;
using System.Reflection;
using System.Windows.Forms;

namespace EventTopicExample
{
    public class Subscriber
    {
        private WorkItem rootWorkItem;

        [ServiceDependency]
        public WorkItem RootWorkItem
        {
            set { rootWorkItem = value; }
        }

        [EventSubscription("MyEvent")]
        public void MyEventHandler(object sender, EventArgs e)
        {
            EventTopic et = rootWorkItem.EventTopics["MyEvent"];
            string message = "EventTopic MyEvent\r\n";
            message += "Number of publications = " + et.PublicationCount.ToString() + "\r\n";
            message += "Number of subscriptions = " + et.SubscriptionCount.ToString() + "\r\n";
            if (et.SubscriptionCount == 1)
            {
                message += "Subscription is MyEventHandler in class Subscirber \r\n";
            }

            MessageBox.Show(message);
        }
    }
}
